import 'package:flutter/material.dart';
import 'dart:async';

class ProgressIndicatorDemo extends StatefulWidget {
	@override
	State<StatefulWidget> createState() {
		return ProgressIndicatorState();
	}
}

class ProgressIndicatorState extends State<ProgressIndicatorDemo> {

	String text = "";
	Timer timer;

	@override
	void initState() {
		super.initState();

		// 使用Timer延迟执行
		var duration = Duration(seconds: 3);
		timer = new Timer(duration ,_fullData);
	}

	@override
	void dispose() {
		timer.cancel();
		super.dispose();
	}

	void _fullData() {
		setState(() {
			text = "hello";
		});
	}

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text("ProgressIndicator"),
			),
			body: _getBody(),
		);
	}

	Widget _getBody() {
		if (text.length == 0) {
			return _emptyBody();
		} else {
			return _normalBody();
		}
	}

	Widget _emptyBody() {
		return Center(
			child: CircularProgressIndicator(),
		);
	}

	Widget _normalBody() {
		return Center(
			child: Text(text),
		);
	}

}